package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.pojo.Permission;
import com.itheima.service.PermissionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author god_97
 * @Date 2020/3/7 14:15
 * @Version 1.0
 */
@RestController
@RequestMapping("/permission")
@Slf4j
public class PermissionController {

    @Reference
    PermissionService permissionService;

    //分页查询
    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean){
        log.debug("controller{"+queryPageBean+"}");
        PageResult pageResult = permissionService.findByPage(queryPageBean);
        log.debug("权限分页查询成功!!");
        return new Result(true, "权限分页查询成功!!", pageResult);
    }

    //查询所有 回显
    @RequestMapping("/findById")
    public Result findById(Integer id){
        log.debug("PermissionController：findById:" + id);
        Permission permission = permissionService.findById(id);
        log.debug("根据id查询权限成功!!");
        return new Result(true, "根据id查询权限成功!!", permission);
    }

    //新增权限
    @RequestMapping("/add")
    public Result add(@RequestBody Permission permission){
        log.debug("controller:{"+permission+"}");
        permissionService.add(permission);
        log.debug("权限添加成功！！");
        return new Result(true, "添加权限成功!!!");
    }

    @RequestMapping("/edit")
    public Result edit(@RequestBody Permission permission){
        log.debug("controller:edit: " + permission);
        permissionService.edit(permission);
        log.debug("修改权限成功！！！");
        return new Result(true, "修改权限成功！！！");
    }

    //删除权限
    @RequestMapping("/delById")
    public Result delById(Integer id){
        log.debug("controller:delete: " + id);
        permissionService.delById(id);
        log.debug("删除权限成功!!");
        return new Result(true, "删除权限成功!!");
    }
    /**
     * @Author tanxinshi
     * @Date 2020/3/9 14:30
     * @Version v1.0
     * @Description 查询
     */
    @RequestMapping("/findAll")
    public Result findAll(){
        log.debug("***********************");
        List<Permission> permissionList = permissionService.findAll();
        log.debug("****************查询权限成功");
        return new Result(true,"查询权限成功",permissionList);
    }
}
